<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/serverUrl.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改密码</h1>
		</header>
		<div class="mui-content">
			<br />
			<div class="mui-input-group">
				<div class="mui-input-row">
					<label>新密码</label>
					<input type="password" id="password1" class="mui-input-password" placeholder="请输入新的密码">
				</div>
				<div class="mui-input-row">
					<label>确认</label>
					<input type="password" id="password2" class="mui-input-password" placeholder="请确认新的密码">
				</div>
				<br />
				<div class="mui-button-row">
					<button type="button" id="ok" class="mui-btn">&nbsp;&nbsp;&nbsp;&nbsp;修改&nbsp;&nbsp;&nbsp;&nbsp;</button>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		document.getElementById("ok").onclick = function(){
			var password1 = document.getElementById("password1").value;
			var password2 = document.getElementById("password2").value
			if (password1 == password2) {
				//如果两次密码一致则修改
				$.ajax({
					//请求方式
					type: "POST",
					dataType: "json",
					url: serverUrl + "resetPassword",
					data: {
						account: localStorage.getItem("account"),
						password: localStorage.getItem("password"),
						newPassword: password2
					},
					//请求成功
					success: function(data) {
						if (data == "success") {
							var userJson = JSON.parse( localStorage.getItem("userInformation") );
							userJson.password = password2;
							localStorage.setItem("userInformation",JSON.stringify(userJson) );
							localStorage.setItem("password",password2);
							mui.toast("修改成功！");
						} else{
							mui.toast(data);
						}
					},
					//请求失败，包含具体的错误信息
					error: function(e) {
						mui.toast("遇到了未知错误！");
					}
				});
			} else{
				mui.toast("两次输入的密码不一致！");
			}
		};
	</script>
</html>
